#include <iostream>
#include <memory>
#include <string>

// 抽象的水果类
class Fruit
{
public:
    Fruit()
    {
    }
    virtual void show() = 0;
};

// 水果类派生出的具体类
class Apple : public Fruit
{
public:
    Apple() {}
    void show() override
    {
        std::cout << "我是一个苹果!" << std::endl;
    }
};

class Banana : public Fruit
{
public:
    Banana() {}
    void show() override
    {
        std::cout << "我是一个香蕉!" << std::endl;
    }
};

//工厂的抽象类
class Factory
{
public:
    virtual std::shared_ptr<Fruit> create() = 0;
};

//为每一个产品抽象一个具体的派生类
class AppleFactory : public Factory
{
public:
    std::shared_ptr<Fruit> create() override
    {
        return std::make_shared<Apple>();
    }
};

class BananaFactory : public Factory
{
public:
    std::shared_ptr<Fruit> create() override
    {
        return std::make_shared<Banana>();
    }
};


int main()
{
    std::shared_ptr<Factory> ft = std::make_shared<AppleFactory>();
    std::shared_ptr<Fruit> fruit = ft->create();
    fruit->show();
    ft = std::make_shared<BananaFactory>();

    return 0;
}
